# # 1. 求 1 - 100 的和
# sum = 0
# for i in range(1, 101):
#     sum += i
# print(sum)
#
# # 2. 求 300 - 400 的和
# sum = 0
# for i in range(300, 401):
#     sum += i
# print(sum)
#
# # 3. 求 1 - 1000 的和
# sum = 0
# for i in range(1, 1001):
#     sum += i
# print(sum)

# 定义函数
# def CalcSum(begin,end):
#     sum = 0
#     for i in range(begin,end + 1):
#         sum += i
#     print(sum)
#
# # 调用函数
# CalcSum(1, 100)
# CalcSum(300, 400)
# CalcSum(1, 1000)

# # 函数调用
# test3() # 还没有执行到定义, 就先执行调用了, 此时就会报错.
# # 函数实现
# def test3():
#     print('hello')

# def test(a, b, c):
#     print(a, b, c)
# test(10)

# def test(a):
#     print(a)
# test(10)
# test('hello')
# test(True)

# def calcSum(begin, end):
#     sum = 0
#     for i in range(begin, end + 1):
#         sum += i
#     print(sum)
#
# calcSum(1, 100)

# def calcSum(begin, end):
#     sum = 0
#     for i in range(begin, end + 1):
#         sum += i
#     return sum
#
# sum = calcSum(1, 100)
# print(sum)

# 判定是否是奇数
# def isOdd(num):
#     if num % 2 == 0:
#         return False
#     else:
#         return True
#
# result = isOdd(10)
# print(result)

# def getPoint():
#     x = 10
#     y = 20
#     return x, y
# a, b = getPoint()

# def getPoint():
#     x = 10
#     y = 20
#     return x, y
# _, b = getPoint()

# def getPoint():
#     x = 10
#     y = 20
#     return x, y
# x, y = getPoint()

# def getPoint():
#     x = 10
#     y = 20
#     return x, y
# getPoint()
# print(x, y)

# x = 20
# def test():
#     x = 10
#     print(f'函数内部 x = {x}')
# test()
# print(f'函数外部 x = {x}')

# x = 20
# def test():
#     print(f'x = {x}')
# test()

# x = 20
# def test():
#     global x
#     x = 10
#     print(f'函数内部 x = {x}')
# test()
# print(f'函数外部 x = {x}')

# for i in range(1, 10):
#     print(f'函数内部 i = {i}')
# print(f'函数外部 i = {i}')

# def test():
#     print("执行函数内部代码")
#     print("执行函数内部代码")
#     print("执行函数内部代码")
# print("1111")
# test()
# print("2222")
# test()
# print("3333")

# def a():
#     print("函数 a")
# def b():
#     print("函数 b")
#     a()
# def c():
#     print("函数 c")
#     b()
# def d():
#     print("函数 d")
#     c()
# d()

# def a():
#     print("函数 a")
# def b():
#     a()
#     print("函数 b")
# def c():
#     b()
#     print("函数 c")
# def d():
#     c()
#     print("函数 d")
# d()

# def factor(n):
#     if n == 1:
#         return 1
#     return n * factor(n - 1) # 自己调用自己
# result = factor(5)
# print(result)

# def factor(n):
#     return n * factor(n - 1)
# result = factor(5)
# print(result)

# def add(x, y, debug=False):
#     if debug:
#         print(f'调试信息: x={x}, y={y}')
#     return x + y
# print(add(10, 20)) # 使用默认值
# print(add(10, 20, True)) # 不使用默认值

# def add(x, debug=False, y): # 默认值放在没有默认值参数前面报错
#     if debug:
#         print(f'调试信息: x={x}, y={y}')
#     return x + y
# print(add(10, 20))

def test(x, y):
    print(f'x = {x}')
    print(f'y = {y}')
test(x=10, y=20)
test(y=100, x=200)